Questions
10 of 45
1What is a pseudo-element in CSS?
2How are pseudo-elements different from pseudo-classes?
3What is the syntax of a pseudo-element?
4Name some commonly used pseudo-elements.
5What does the ::before pseudo-element do? What does the ::after pseudo-element do?
6How can you insert content using pseudo-elements?
7What is the difference between :before and ::before? Why were pseudo-elements changed from one colon (:) to two (::) in CSS3?
8What does the ::first-letter pseudo-element do?
9What does the ::first-line pseudo-element do?
10How can you style the first line of a paragraph differently?
11Can pseudo-elements be styled with animations or transitions?
12What’s the difference between using ::before and ::after?
13Can pseudo-elements be positioned using CSS positioning properties? Can pseudo-elements have background images or colors? How can you use pseudo-elements to create shapes or icons?
14Can you use multiple pseudo-elements on the same element?
15What is the ::selection pseudo-element used for?
16How does stacking and z-index affect pseudo-elements?
17Can pseudo-elements have child elements or content inside them?
18Can you apply pseudo-elements to replaced elements (like <img>)?
19How do pseudo-elements interact with display and overflow properties?
20What’s the difference between using pseudo-elements and real elements for decoration?
21How does inheritance work with pseudo-elements?
22Can pseudo-elements trigger JavaScript events (like click)?
23How can you control the generated content with pseudo-elements using attr()?
24Can pseudo-elements be used inside flex or grid layouts?
25How do you control the stacking order of ::before and ::after pseudo-elements?
26How can you create a tooltip using pseudo-elements?
27How can you make a custom underline or highlight effect using ::after?
28How can you make a quotation mark appear before a paragraph using pseudo-elements?
29How do you create a triangle or arrow shape using only CSS pseudo-elements?
30How can you use pseudo-elements to add icons without extra markup?
31How can you create a button hover animation using ::before or ::after?
32How can pseudo-elements help in implementing skeleton loaders or shimmer effects?
33How can you use ::before and ::after to clear floats?
34How can you create a border animation using pseudo-elements?
35How can pseudo-elements be used in responsive design?
36What is the ::marker pseudo-element and when is it used?
37What does the ::placeholder pseudo-element do?
38How does ::cue work with media elements?
39What is ::backdrop, and where is it used?
40What is the difference between ::file-selector-button and other input pseudo-elements?
41How does the ::part() pseudo-element work in Web Components?
42How is ::slotted() different from ::part() in shadow DOM styling?
43Can you style text highlights with pseudo-elements?
44How can ::selection be customized for accessibility and branding?
45What are the limitations of pseudo-elements compared to actual DOM elements?
10 / 45

How can you style the first line of a paragraph differently?

Styling the First Line of a Paragraph Using ::first-line

The ::first-line pseudo-element in CSS allows you to style only the first line of a block-level element. This is helpful for adding emphasis, decorative effects, or visual hierarchy to the start of a paragraph.

Key Points
  1. 1

    ::first-line targets only the first rendered line of text within a block element.

  2. 2

    It can be styled with text-related properties such as color, font-size, font-weight, letter-spacing, and word-spacing.

  3. 3

    It works exclusively on block-level elements like <p>, <div>, or <section>.

  4. 4

    It cannot insert content; it only modifies the appearance of the existing text.

Example: Applying Styles to the First Line

Here, only the first line of the paragraph is styled differently, providing emphasis while the rest of the paragraph remains normal.

Best Practices
  1. 1

    Use ::first-line to highlight or emphasize the start of paragraphs.

  2. 2

    Stick to text-related CSS properties for consistent results.

  3. 3

    Consider responsive layouts, as the first line may wrap differently on various screen sizes.

  4. 4

    Combine with ::first-letter for advanced typographic effects.

Difficulty: 3/10
Topics: first-line styling, CSS pseudo-elements, line-height inheritance

Scenario Questions

0-2 years experience
  1. 1

    How would you make the first line of a paragraph red and bold using CSS?

  2. 2

    What happens if you try to set margin-top on ::first-line? Why?

2-5 years experience
  1. 1

    A designer says the first line of all article paragraphs should be italicized, but it’s not working on mobile — what would you check?

  2. 2

    We’re seeing inconsistent first-line styling across browsers in our blog component — how would you debug and fix this?

5-8 years experience
  1. 1

    We’re building a rich-text editor where users can style the first line of paragraphs — how would you implement this reliably without breaking layout or performance on long-form content?

  2. 2

    How would you handle first-line styling in a component that dynamically switches between block and inline-display based on screen size?

8+ years experience
  1. 1

    Our content platform has legacy CSS that uses JavaScript to simulate first-line styling — how would you migrate to native CSS ::first-line without breaking existing layouts or accessibility?

  2. 2

    When designing a global typography system, how do you balance the use of ::first-line with accessibility, performance, and internationalization concerns across 50+ languages?

Follow-up Questions

  • What happens if you apply margin or padding to ::first-line?
  • Why won't this work if the paragraph is inside a flex container?
  • How would you test this across mobile and desktop breakpoints?